package com.hp.attendance.serlvet.employee;

import com.hp.attendance.entity.EmpRole;
import com.hp.attendance.entity.RoleMenu;
import com.hp.attendance.service.EmployeeService;
import com.hp.attendance.service.RoleService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet("/empAddDistri")
public class RoleAddDistriServlet extends HttpServlet {
    private EmployeeService employeeService = new EmployeeService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //分配菜单
        int empId = Integer.parseInt(req.getParameter("empId"));
        String[] roleIds = req.getParameterValues("rolecheck");
        ArrayList<EmpRole> list = new ArrayList<EmpRole>();
        if (roleIds!=null){
            for (int i = 0; i < roleIds.length; i++) {
                int menuId = Integer.parseInt(roleIds[i]);
                list.add(new EmpRole(empId,menuId));
            }
        }
        employeeService.distriRole(list,empId);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
